package com.aspose.cells;

class zcez {
   static Object a(zcfe var0, zabd var1, Cell var2) {
      if (var1.d() != null && (var1.d().size() == 4 || var1.d().size() == 3)) {
         Object var3 = var0.b((zabd)var1.d().get(0), var2);
         if (var3 == null) {
            var3 = 0.0D;
         }

         Object var4 = null;
         boolean var5 = false;
         zabd var6 = (zabd)var1.d().get(1);
         boolean var7 = true;
         Object var8 = zyn.e(var0.b((zabd)var1.d().get(2), var2), var0.e.getSettings().getDate1904());
         if (var8 instanceof Double) {
            int var15 = (int)com.aspose.cells.a.c.zi.b(var8) - 1;
            if (var15 < 0) {
               return zst.i;
            } else {
               var4 = var0.b((zabd)var1.d().get(1), var2);
               if (var4 == null) {
                  return var4;
               } else if (var4 instanceof zst) {
                  return var4;
               } else {
                  zft var9 = new zft();
                  if (var4 instanceof zft) {
                     var9 = (zft)var4;
                     var4 = var0.a(var1, var0.e.getWorksheets().get(var9.b), var2, var9.d.StartRow, var9.d.StartRow, var9.d.StartColumn, var9.d.EndColumn);
                     var5 = true;
                     if (var15 > var9.d.EndRow - var9.d.StartRow) {
                        return zst.g;
                     }
                  }

                  if (!com.aspose.cells.a.c.zc.a(var4)) {
                     return zst.g;
                  } else {
                     boolean var10 = true;
                     if (var1.d().size() == 4) {
                        Object var11 = var0.b((zabd)var1.d().get(3), var2);
                        if (var11 instanceof zst) {
                           return var11;
                        }

                        if (var11 != null) {
                           switch(zamo.a(var11.getClass())) {
                           case 3:
                              var10 = (Boolean)var11;
                              break;
                           case 14:
                              if ((Double)var11 == 0.0D) {
                                 var10 = false;
                              }
                              break;
                           case 16:
                              double var12 = CellsHelper.getDoubleFromDateTime((DateTime)var11, var0.e.getSettings().getDate1904());
                              if (var12 == 0.0D) {
                                 var10 = false;
                              }
                              break;
                           case 18:
                              return zst.i;
                           }
                        }
                     }

                     boolean var16 = false;
                     Object var18 = a(var0, var3, var4, var10);
                     if (var18 instanceof Double) {
                        int var17 = (int)com.aspose.cells.a.c.zi.b(var18);
                        if (var5) {
                           Cell var19 = var0.e.getWorksheets().get(var9.b).getCells().checkCell(var9.d.StartRow + var15, var9.d.StartColumn + var17);
                           return var19 == null ? null : var0.a(var19);
                        } else {
                           Object[] var13 = (Object[])((Object[])var4);
                           if (var15 >= var13.length) {
                              return zst.g;
                           } else {
                              Object[] var14 = (Object[])((Object[])com.aspose.cells.b.a.za.a(var13, var15));
                              return com.aspose.cells.b.a.za.a(var14, var17);
                           }
                        }
                     } else {
                        return var18;
                     }
                  }
               }
            }
         } else {
            return zst.i;
         }
      } else {
         throw new CellsException(5, "Invalid formula in " + var2.d.h().getName() + ":" + var2.i());
      }
   }

   private static Object a(zcfe var0, Object var1, Object var2, boolean var3) {
      int var4 = -1;
      if (var1 instanceof zst) {
         return var1;
      } else {
         if (var1 instanceof Object[][]) {
            var1 = ((Object[][])((Object[][])var1))[0][0];
         }

         if (var1 == null) {
            var1 = 0.0D;
         }

         switch(zamo.a(var1.getClass())) {
         case 3:
            boolean var12 = (Boolean)var1;
            Object[] var13 = (Object[])((Object[])com.aspose.cells.b.a.za.a((Object[])((Object[])((Object[])var2)), 0));

            for(int var14 = 0; var14 < var13.length; ++var14) {
               Object var10 = com.aspose.cells.b.a.za.a(var13, var14);
               if (var10 != null && var10 instanceof Boolean && var12 == (Boolean)var10) {
                  return (double)var14;
               }
            }

            return zst.c;
         case 14:
            return a(var0, com.aspose.cells.a.c.zi.b(var1), (Object[])((Object[])var2), var3);
         case 16:
            double var11 = CellsHelper.getDoubleFromDateTime((DateTime)var1, var0.e.getSettings().getDate1904());
            return a(var0, var11, (Object[])((Object[])var2), var3);
         case 18:
            String var5 = (String)var1;
            var5 = var5.toUpperCase();
            Object[] var6 = (Object[])((Object[])com.aspose.cells.b.a.za.a((Object[])((Object[])((Object[])var2)), 0));

            for(int var7 = 0; var7 < var6.length; ++var7) {
               Object var8 = com.aspose.cells.b.a.za.a(var6, var7);
               if (var8 != null) {
                  String var9 = com.aspose.cells.b.a.zr.a(var8).toUpperCase();
                  if (com.aspose.cells.b.a.zv.b(var9, var5)) {
                     return (double)var7;
                  }

                  if (var3 && var5.indexOf(var9) != -1) {
                     var4 = var7;
                  }
               }
            }

            if (var3) {
               if (var4 != -1) {
                  return (double)var4;
               }

               return zst.c;
            }

            return zst.c;
         default:
            return zst.i;
         }
      }
   }

   private static Object a(zcfe var0, double var1, Object[] var3, boolean var4) {
      if (var4) {
         int var5 = -1;
         Object[] var6 = (Object[])((Object[])com.aspose.cells.b.a.za.a((Object[])var3, 0));
         int var7 = var6.length;

         for(int var8 = 0; var8 < var7; ++var8) {
            Object var9 = com.aspose.cells.b.a.za.a(var6, var8);
            if (var9 != null) {
               var9 = zyn.e(var9, var0.e.getSettings().getDate1904());
               if (var9 instanceof Double) {
                  double var10 = (Double)var9;
                  if (Math.abs(var1 - var10) < Double.MIN_VALUE) {
                     if (var8 == var7 - 1) {
                        return (double)var8;
                     }

                     var5 = var8;

                     while(true) {
                        ++var8;
                        if (var8 == var7) {
                           return (double)var5;
                        }

                        Object var12 = com.aspose.cells.b.a.za.a(var6, var8);
                        if (var12 == null && var5 >= var7 / 2) {
                           return (double)var5;
                        }

                        var12 = zyn.e(var12, var0.e.getSettings().getDate1904());
                        if (var12 instanceof Double) {
                           double var13 = (Double)var12;
                           if (Math.abs(var1 - var13) >= Double.MIN_VALUE) {
                              return (double)var5;
                           }

                           var5 = var8;
                        } else if (var5 >= var7 / 2) {
                           return (double)var5;
                        }
                     }
                  }

                  if (var10 < var1) {
                     var5 = var8;
                  }
               }
            }
         }

         if (var5 != -1) {
            return (double)var5;
         }
      } else {
         Object[] var15 = (Object[])((Object[])com.aspose.cells.b.a.za.a((Object[])var3, 0));

         for(int var16 = 0; var16 < var15.length; ++var16) {
            Object var17 = com.aspose.cells.b.a.za.a(var15, var16);
            if (var17 != null) {
               var17 = zyn.e(var17, var0.e.getSettings().getDate1904());
               if (var17 instanceof Double && Math.abs(var1 - (Double)var17) < Double.MIN_VALUE) {
                  return (double)var16;
               }
            }
         }
      }

      return zst.c;
   }
}
